from typing import Dict

from fastapi import FastAPI, Request

import uvicorn
import json
from fastapi import Body

from generate_vector import VectorData

embedding_path = r"D:\huggingface\modelscope\hub\bge-base-zh-v1.5"
vectordata = VectorData('data/demo.json', embedding_path=embedding_path, collection_name="p8_1")

app = FastAPI()

@app.get("/")
def start(
        query: str = Body(..., description="问题"),
    ) -> Dict:
    # answer = vectordata.vector_search(query)
    answer = "first"
    return {"code": 200, "answer": answer}
@app.post("/query_from_milvus")
def query_from_milvus(
            query: str = Body(..., description="问题"),
            ttt: str =  Body(..., description="ttttt")

    ) -> Dict:
    print("xiayu query",query)
    #print("xiayu tttt", ttt)
    answer = vectordata.vector_search(query)
    #answer = "first"
    return {"code": 200, "answer": answer}

if __name__ == "__main__":


    uvicorn.run(app, host='0.0.0.0', port=6006, workers=1)